package com.renbang.action.test;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.renbang.action.BaseAction;
import com.renbang.model.common.AjaxResult;
import com.renbang.model.common.Page;
import com.renbang.model.test.Stu;
import com.renbang.service.test.StuService;
/**
 * 该代码由程序生成
 */
@Controller
@RequestMapping(value = "user/test/Stu")
public class StuAction  extends BaseAction<Stu>{
	@Autowired
	StuService stuService;
	
	@RequestMapping(value = "/dels")
	public @ResponseBody AjaxResult dels(String[] ids) {
		System.out.println(ids);
		List <String> idList = Arrays.asList(ids);
		System.out.println(idList);
		//Integer num = stuService.removeByIds(idList);
		return new AjaxResult(AjaxResult.STATUS_OK, "成功删除"+0+"条");
	}
	
	//打开新增或修改页面
	@RequestMapping(value = "/editForm")
	public String editForm(Integer id, HttpServletRequest request) {
		Stu stu;
		if (id != null) {
			stu = stuService.findById(id);
			request.setAttribute("obj", stu);
		}
		return "user/test/Stu-form";
	}
	@RequestMapping(value = "/addOrModify")
	public  @ResponseBody AjaxResult insertOrUpdata(HttpServletRequest request,
	Stu stu) {
		if(stu.getId()!=null){
			int i = stuService.modify(stu);
			if (i > 0)
				return new AjaxResult(AjaxResult.STATUS_OK, "修改成功");
			else
				return new AjaxResult(AjaxResult.STATUS_OK, "修改失败");
	} else {
		 int i = stuService.add(stu);
		 if (i > 0)
		 	return new AjaxResult(AjaxResult.STATUS_OK, "增加成功");
		 else
			return new AjaxResult(AjaxResult.STATUS_OK, "增加失败");
	}
		
	}
	
}
